package com.snails.app.utils;

import android.app.Activity;
import android.content.Context;

import com.snails.app.R;

/**
 * activity 辅助类
 * @author lawrence
 * @date 2019-05-10 11:10
 */
public final class ActivityHelper {
    public interface SFunction {
        void doSomething();
    }

    // ----------------------------------------------------------------------------
    // -----------  ------------
    // ----------------------------------------------------------------------------
    private ActivityHelper() { }

    // 调用activity的overridePendingTransition实现切换动画
    private static void overridePendingTransition(Context ctx, int enterAnim, int exitAnim) {
        if (ctx != null && ctx instanceof Activity) {
            Activity activity = (Activity) ctx;
            activity.overridePendingTransition(enterAnim, exitAnim);
        }
    }

    /**
     * 打开新页面
     */
    public static void startAnim(Context ctx, SFunction function) {
        if (function != null) function.doSomething();
        overridePendingTransition(ctx, R.anim.slide_in_right, R.anim.slide_out_right);
    }

    /**
     * 关闭当前页面
     */
    public static void finishAnim(Context ctx, SFunction function) {
        if (function != null) function.doSomething();
        overridePendingTransition(ctx, R.anim.slide_in_left, R.anim.slide_out_left);
    }

    /**
     * 打开新页面
     */
    public static void startAnim(Context ctx, SFunction function, int enterAnim, int exitAnim) {
        if (function != null) function.doSomething();
        overridePendingTransition(ctx, enterAnim, exitAnim);
    }

    /**
     * 关闭当前页面
     */
    public static void finishAnim(Context ctx, SFunction function, int enterAnim, int exitAnim) {
        if (function != null) function.doSomething();
        overridePendingTransition(ctx, enterAnim, exitAnim);
    }

}
